using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.RequestOfficeSupplies.BLL.Common;
using XQ.RequestOfficeSupplies.DAL.DAL.Business;
using XQ.RequestOfficeSupplies.DAL.Model.Business;
using XQ.RequestOfficeSupplies.DAL.Model;
using XQ.RequestOfficeSupplies.DAL.Models;
using XQ.RequestOfficeSupplies.DAL;

namespace XQ.RequestOfficeSupplies.BLL.Business
{
    public class WarehouseBLL
    {
        WarehouseDal warehouseDal = new WarehouseDal();

        public List<WarehouseReturnModel> GetList(WarehouseSearchModel ssm, Pagination page, TokenModel token)
        {
            return warehouseDal.GetList(ssm, page, token);
        }

        public Guid SaveWarehouse(Warehouse warehouse, TokenModel token)
        {
            Guid WarehouseID = warehouse.id;
            bool isSuccess = false;
            DateTime curTime = DateTime.Now;
            if (warehouse != null && warehouse.id != Guid.Empty)
            {
                //修改
                isSuccess = warehouseDal.UpdateModel(warehouse) > 0;

            }
            else
            {
                //新增
                Warehouse warehouseInfo = warehouseDal.AddModel(warehouse);
                WarehouseID = warehouseInfo.id;

            }

            return WarehouseID;
        }

        public WarehouseReturnModel GetWarehouseByID(Guid id)
        {
            WarehouseReturnModel warehouseModel = new WarehouseReturnModel();
            Warehouse warehouse = warehouseDal.FindModel(c => c.id == id);
            warehouseModel = ClassHelper.ParentCopyToChild<Warehouse, WarehouseReturnModel>(warehouse);

            return warehouseModel;
        }


        public int DeleteByIds(List<Guid> ids)
        {
            return warehouseDal.DeleteModel(c => ids.Contains(c.id));
        }
    }
}
